using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;
namespace MemoryGame
{
    public class TBitmaps
    {
        public Texture2D[] bitmaps;
        public int n;
        public int height, width;
        public int height_half, width_half;
        public float scale_x, scale_y;
        public TBitmaps()
        {
        }
        public TBitmaps(string filename, int i1, int i2, int nwidth, int nheight)
        {

            n = i2 - i1 + 1;
            bitmaps = new Texture2D[n];
            for (int i = i1; i <= i2; i++)
            {
                bitmaps[i - i1] = Game1.contentManager.Load<Texture2D>(filename + i);
            }
            if (nheight == -1 && nwidth == -1)
            {
                width = bitmaps[0].Width;
                height = bitmaps[0].Height;
            }
            else if (nheight == -1)
            {
                width = nwidth;
                height = (int)(width * bitmaps[0].Height * 1.0f / bitmaps[0].Width);
            }
            else if (nwidth == -1)
            {
                height = nheight;
                width = (int)(height * bitmaps[0].Width * 1.0f / bitmaps[0].Height);
            }
            else
            {
                width = nwidth;
                height = nheight;
            }
            scale_x = width * 1.0f / bitmaps[0].Width;
            scale_y = height * 1.0f / bitmaps[0].Height;
            height_half = height / 2;
            width_half = width / 2;
        }
        public void Draw(ref SpriteBatch c, int index, int x, int y)
        {
            c.Draw(bitmaps[index], new Vector2(x, y), null, Color.White, 0f, new Vector2(0, 0), new Vector2(scale_x, scale_y), SpriteEffects.None, 1);
            
        }
        public void Draw(SpriteBatch c, int index, int x, int y)
        {
            c.Draw(bitmaps[index], new Vector2(x, y), null, Color.White, 0f, new Vector2(0, 0), new Vector2(scale_x, scale_y), SpriteEffects.None, 1);

        }
        public void DrawCenter(ref SpriteBatch c, int index, int x, int y)
        {
            c.Draw(bitmaps[index], new Vector2(x - width_half, y - height_half), null, Color.White, 0f, new Vector2(0, 0), new Vector2(scale_x, scale_y), SpriteEffects.None, 1);
        }
        public void DrawCenter(ref SpriteBatch c, int index, int x, int y,int alpha)
        {
            c.Draw(bitmaps[index], new Vector2(x - width_half, y - height_half), null, new Color(0,0,0,alpha), 0f, new Vector2(0, 0), new Vector2(scale_x, scale_y), SpriteEffects.None, 1);
        }
    }
}
